package org.jeecg.jxc.homepage.api.vo;


import org.jeecg.jxc.homepage.api.constant.CommonConstant;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 成功标志
     */
    private boolean success = true;

    /**
     * 返回处理消息
     */
    private String message = "操作成功！";

    /**
     * 返回状态码
     */
    private Integer code = 0;

    /**
     * 返回数据对象
     */
    private T result;

    /**
     * 时间戳
     */
    private long timestamp = System.currentTimeMillis();

    public static<T> Result<T> OK() {
        Result<T> rs = new Result<T>();
        rs.setSuccess(true);
        rs.setCode(CommonConstant.SC_OK_200);
        rs.setMessage("操作成功！");
        return rs;
    }

    public static<T> Result<T> OK(T data) {
        Result<T> rs = new Result<T>();
        rs.setSuccess(true);
        rs.setCode(CommonConstant.SC_OK_200);
        rs.setResult(data);
        return rs;
    }

    public static<T> Result<T> OK(String msg, T data) {
        Result<T> rs = new Result<T>();
        rs.setSuccess(true);
        rs.setCode(CommonConstant.SC_OK_200);
        rs.setMessage(msg);
        rs.setResult(data);
        return rs;
    }

    public static Result<Object> error(String msg) {
        return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result<Object> rs = new Result<Object>();
        rs.setCode(code);
        rs.setMessage(msg);
        rs.setSuccess(false);
        return rs;
    }
}